package com.example;

import com.alibaba.druid.pool.DruidDataSource;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

/**
 * @author lbq
 * @version 1.0
 * @date 2021/11/24 22:20
 */
public class Test1 {
    public static void main(String[] args) throws SQLException {
        final DruidDataSource druidDataSource = new DruidDataSource();
        druidDataSource.setUrl("jdbc:mysql://node2:3306/lagou_study?serverTimezone=Asia/Shanghai&useSSL=false&allowPublicKeyRetrieval=true");
        druidDataSource.setDriverClassName("com.mysql.jdbc.Driver");
        druidDataSource.setUsername("hive");
        druidDataSource.setPassword("12345678");
        Connection connection = druidDataSource.getConnection();
        PreparedStatement preparedStatement = connection.prepareStatement("select * from r_user");
        ResultSet resultSet = preparedStatement.executeQuery();
        while (resultSet.next()) {
            System.out.println("id : " + resultSet.getString(1));
            System.out.println("email : " + resultSet.getString(2));
            System.out.println("password : " + resultSet.getString(3));
            System.out.println("register_time : " + resultSet.getString(4));
        }
        resultSet.close();
        preparedStatement.close();
        connection.close();
    }
}
